package com.s3.khospitalds.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.s3.khospitalds.entity.Patientlist;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author: xw
 * @CreateTime: 2025/2/25
 * @Description: 处理药方表
 * @Version: 1.0
 */
@Mapper
@Repository
public interface PatientlistMapper extends BaseMapper<Patientlist> {
    @Select("SELECT * FROM patientlist WHERE waitingNumber=#{num} \n")
    public List<Patientlist> selectWaitingNumber(int num);
    @Select("SELECT * FROM patientlist WHERE number=#{num} \n")
    public List<Patientlist> selectPatientNumber(String num);
    @Select("SELECT * FROM patientlist WHERE waitingNumber = 0\n")
    public List<Patientlist> selectWaitingNumber0();
    @Select("SELECT * FROM patientlist WHERE waitingNumber = 2\n")
    public List<Patientlist> selectWaitingNumber2();
    @Select("SELECT * FROM patientlist WHERE number LIKE concat('%',#{number},'%') AND `name` LIKE concat('%',#{name},'%')")
    public List<Patientlist> selectNameAndNumber(@Param("number") String number, @Param("name") String name);
    @Select("SELECT * FROM patientlist WHERE `name` LIKE concat('%',#{name},'%')")
    public List<Patientlist> selectName( @Param("name") String name);
    @Select("SELECT * FROM patientlist WHERE number LIKE concat('%',#{number},'%')")
    public List<Patientlist> selectNumber(@Param("number") String number);
    @Update("UPDATE patientlist SET waitingNumber=0 WHERE number=#{number} ")
    public int updateWaitingNumber(String number);
    @Update("UPDATE patientlist SET waitingNumber=2 WHERE number=#{number} ")
    public int updateWaitingNumber2(String number);
    @Update("UPDATE patientlist SET pharmacist=#{pharmacist}  WHERE number=#{number} \n")
    public int updatePharmacist(@Param("pharmacist")String pharmacist, @Param("number") String number);
    @Insert("INSERT INTO patientList (`date`, number, `name`, sex, region, familyName, phone, relation, illHistory, idCard, age, symptoms, disease, `position`, address, doctor, pharmacist, waitingNumber, copayFee) VALUES\n" +
            "(#{patientlist.date} ,#{patientlist.number} , #{patientlist.name} , #{patientlist.sex} , #{patientlist.region} , #{patientlist.familyName} , #{patientlist.phone} , #{patientlist.relation} ,'没有' , #{patientlist.idCard} , #{patientlist.age} , #{patientlist.symptoms}, #{patientlist.disease} , #{patientlist.position} , #{patientlist.address} , #{patientlist.doctor} , NULL, #{patientlist.waitingNumber}, NULL)")
    public int insertPatientList(@Param("patientlist") Patientlist patientlist);
    @Update("UPDATE `patientlist` SET `date`=#{patientlist.date} ,`name`=#{patientlist.name} ,sex=#{patientlist.sex} ,region=#{patientlist.relation} ,familyName=#{patientlist.familyName} ,phone=#{patientlist.phone} ,relation=#{patientlist.region} ,illHistory=#{patientlist.illHistory} ,idCard=#{patientlist.idCard} ,age=#{patientlist.age} ,symptoms=#{patientlist.symptoms} ,disease=#{patientlist.disease} ,address=#{patientlist.address} ,`doctor`=#{patientlist.doctor}  WHERE id=#{patientlist.id} ")
    public int updatePatientList(@Param("patientlist") Patientlist patientlist);
    @Delete("DELETE FROM `patientlist` WHERE number= #{number} ")
    public int deletePatientList(String number);
    @Insert("INSERT INTO patientlist (`date`,number, `name`, sex, region, age, phone, idCard, disease, doctor, copayFee, position) " +
            "VALUES (#{date},#{number}, #{name}, #{sex}, '门诊', #{age}, #{phone}, #{idCard}, #{disease}, #{doctor}, #{copayFee}, #{position})")
    int insertPatientList2(
            @Param("date") String date,
            @Param("number") String number,
            @Param("name") String name,
            @Param("sex") String sex,
            @Param("age") int age,
            @Param("phone") String phone,
            @Param("idCard") String idCard,
            @Param("disease") String disease,
            @Param("doctor") String doctor,
            @Param("position") String position,
            @Param("copayFee") String copayFee
    );
    @Update("UPDATE `patientlist` SET totalPrice=#{price}   WHERE number=#{number} ")
    public int updateTotalPrice(@Param("price")double price,@Param("number") String number);
}